#!/bin/bash
projectPath=$1
branch=$2
cloneUrl=$3
install=$4

# 克隆项目到项目根目录的临时文件夹
git clone $cloneUrl ./temporary

# 切换目标分支并拷贝项目到目标项目文件夹
cd ./temporary
git checkout $branch
cd ..
cp -rf ./temporary/* $projectPath

# 删除临时文件夹
rm -rf ./temporary

# 如果install参数是1则执行下载项目依赖
if [ $install == '1' ]
then
  cd $projectPath
  source ~/.nvm/nvm.sh
  nvm use 14.16.0
  yarn install
fi